package cn.mesmile.flow.listen;

import cn.hutool.core.convert.Convert;
import cn.hutool.extra.spring.SpringUtil;
import org.flowable.engine.RuntimeService;
import org.flowable.engine.TaskService;
import org.flowable.task.service.delegate.DelegateTask;
import org.flowable.task.service.delegate.TaskListener;
import org.springframework.stereotype.Component;

/**
 * @author zb
 * @date 2021/10/25 18:21
 * @Description 设计变更  》 验证人
 * 		cn.mesmile.flow.listen.BomUpgradeVerifyPersonListener
 */
@Component
public class BomUpgradeVerifyPersonListener implements TaskListener {

	@Override
	public void notify(DelegateTask delegateTask) {
		// 动态设置审批人
		TaskService taskService = SpringUtil.getBean(TaskService.class);
		RuntimeService runtimeService = SpringUtil.getBean(RuntimeService.class);
		// 获取验证人的值
		Object variable = runtimeService.getVariable(delegateTask.getExecutionId(), "字段名");
		if (variable != null){
			String bomUpgradeVerifyPerson = Convert.toStr(variable);
			// 设置审批人
			taskService.setAssignee(delegateTask.getId(), bomUpgradeVerifyPerson);
		}
	}
}